/*
* Copyright (C) 2012  lidp.
*
* Contact: lidp <openser@yeah.org>
*	
* This file is part of Open Source Peasant Framework.
*
* Peasant is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*	
* You should have received a copy of the GNU General Public License
* along with Peasant.
*
*/

/**@file pst_mem.c
 * @brief memeory manager  utilities with logger
 *
 */

#include "pst_mem.h"
#include "pst_logger.h"


#include <stdarg.h>
#include <ctype.h>
#include <stdio.h>

void* pst_malloc(pst_size_t size)
{
	void *ptr = PST_NULL;
	if(!(ptr = malloc(size)))
		pst_log(LOG_ERROR, "failed to malloc memory!\n");

	return ptr;
}

void* pst_calloc(pst_size_t num, pst_size_t len)
{
	void *ptr = PST_NULL;
	if(!(ptr = calloc(num, len)))
		pst_log(LOG_ERROR, "failed to calloc memory!\n")

	return ptr;
}

void pst_realloc(void * ptr, pst_size_t len)
{
	void *ptr = PST_NULL;
	if(!(ptr = realloc(ptr, len)))
		pst_log(LOG_ERROR, "failed to realloc memory!\n");

	return ptr;
}

void pst_free(void **ptr)
{
	if(ptr && *ptr) {
		free(*ptr);
		*ptr = PST_NULL;
	}
}